package com.anzia.study_1.slice;

import com.anzia.study_1.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT;
import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT;

public class SecondAbilitySlice extends AbilitySlice {
	@Override
	public void onStart(Intent intent) {
		super.onStart(intent);
		// 编程的方式实现布局，主要在这里实现
		// 声明一个布局
		DependentLayout myLayout = new DependentLayout(this);

		// 给布局设置宽和高，还有背景
		myLayout.setHeight(MATCH_PARENT);
		myLayout.setWidth(MATCH_PARENT);

		ShapeElement element = new ShapeElement();
		element.setRgbColor(new RgbColor(255,255,255));

		myLayout.setBackground(element);

		// 构造一个文本组件
		Text text = new Text(this);
		text.setText("这是我们做的一个鸿蒙应用的第二张页面");
		text.setTextColor(Color.BLACK);
		text.setTextSize(20, Text.TextSizeType.FP);

		// 文本组件的布局设置
		DependentLayout.LayoutConfig layoutConfig = new DependentLayout.LayoutConfig(MATCH_CONTENT, MATCH_CONTENT);
		layoutConfig.addRule(DependentLayout.LayoutConfig.CENTER_IN_PARENT);
		text.setLayoutConfig(layoutConfig);

		// 添加组件
		myLayout.addComponent(text);

		// 声明UI布局，显示到屏幕上去
		super.setUIContent(myLayout);

	}

	@Override
	public void onActive() {
		super.onActive();
	}

	@Override
	public void onForeground(Intent intent) {
		super.onForeground(intent);
	}
}
